/**
 * @author		Sergey Suzdalskiy
 * @e-mail:		sergey.suzdalskiy@gmail.com
 */
package ua.kiev.gcore.ui.controls
{
	import flash.display.DisplayObject;
	import flash.display.Sprite;
	import flash.events.Event;
	
	public class Box extends Sprite
	{
		protected var _spacing:Number;
		protected var position:int;
		
		public function Box()
		{
			super();
			_spacing = 0;
		}
		
		public function set spacing(value:Number):void{
			if(value){
				if(!_spacing){
					_spacing = value;
					resize();
				}else{
					if(_spacing != value){
						_spacing = value;
						resize();
					}	
				}
			}
		}
		public function get spacing():Number{
			return _spacing;
		}
		
		public function clear():void{
			while(numChildren){
				var child:DisplayObject = super.removeChildAt(0);
				child.removeEventListener(Event.RESIZE, resizeHandler);
			}
		}
		
		override public function addChild(child:DisplayObject):DisplayObject{
			child = super.addChild(child);
			resize();
			child.addEventListener(Event.RESIZE, resizeHandler);
			return child;
		}
		
		override public function addChildAt(child:DisplayObject, index:int):DisplayObject{
			child = super.addChildAt(child, index);
			resize();
			child.addEventListener(Event.RESIZE, resizeHandler);
			return child;
		}
		
		override public function removeChild(child:DisplayObject):DisplayObject{
			child = super.removeChild(child);
			resize();
			child.removeEventListener(Event.RESIZE, resizeHandler);
			return child;
		}
		
		override public function removeChildAt(index:int):DisplayObject{
			var child:DisplayObject = super.removeChildAt(index);
			resize();
			child.removeEventListener(Event.RESIZE, resizeHandler);
			return child;
		}
		
		protected function resizeHandler(event:Event):void{
			resize();
		}
		
		protected function resize():void{
			
		}
	}
}